package com.bbb.blogservice.service.blog;

import com.bbb.blogservice.dao.blog.BLogDao;
import com.bbb.blogservice.entity.BlogContent;
import com.bbb.blogservice.entity.BlogInfo;
import com.bbb.blogservice.entity.BlogTopic;
import com.bbb.blogservice.entity.BlogVideo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service(value = "blogService")
public class BlogServiceImpl implements  BlogService {

    @Autowired
    BLogDao blogDao;

    @Override
    public void saveTopic(BlogTopic blogTopic) {
        blogDao.saveTopic(blogTopic);
    }

    @Override
    public void updateTopic(BlogTopic blogTopic) {
        blogDao.updateTopic(blogTopic);
    }

    @Override
    @Transactional
    public void createBlog(BlogInfo blogInfo, BlogContent blogContent) {

        blogDao.saveBlogInfo(blogInfo);

        blogDao.saveBlogContent(blogContent);
    }

    @Override
    @Transactional
    public void saveBlog(BlogContent blogContent, BlogInfo blogInfo) {

        blogDao.updateBlogInfo(blogInfo);

        blogDao.updateBlogContent(blogContent);
    }

    @Override
    public List<BlogTopic> getAllTopicByUser(Long userId) {
        return blogDao.getAllTopicByUser(userId);
    }

    @Override
    public List<BlogInfo> getAllBlogByTopicId(String topicId) {
        return blogDao.getAllBlogByTopicId(topicId);
    }

    @Override
    public Map<String, Object> getBlogById(Long id) {
        return blogDao.getBlogById(id);
    }

    @Override
    public List<BlogInfo> getAllBlog() {
        return blogDao.getAllBlog();
    }

    @Override
    public List<BlogVideo> getBlogVideo(Long blogId) {
        return blogDao.getBlogVideo(blogId);
    }
}
